Template Literals 與 Destructuring


Posted by cmtilo on 2021-04-30

再也不需要字串拼接:Template Literals

、、 可以放多行字串

例1

var str =、
hey
hi
、

例2

console.log(、hello, ${name.toUpperCase} now is ${new Date( )}、)

聽起來很酷的 Destructuring:解構

例1

const arr = [1, 2, 3, 4]
var [first, second, third, fourth] = arr

例2

const obj = {
 name : 'nick'
 age : 30
 address : 'taiwan'
}
var {name, age, address} = obj

例3

function test({a, b}) {
 console.log(a)
}
test({
 a : 1,
 b : 2
})

#template literals #destructuring







Related Posts

[JS] 浮點數精度問題

[JS] 浮點數精度問題

MTR04_0828

MTR04_0828

Letter Combinations of a Phone Number

Letter Combinations of a Phone Number


Comments